package com.example.springboot.loader;

import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

/**
 * 获取Resource文件夹下的文件
 */
@Component
public class FileLoader {
    private final ResourceLoader resourceLoader;

    public FileLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

    /**
     * 获Resource中的文件
     * @return
     * @throws IOException
     */
    public File loadFile(String path) throws IOException {
        Resource resource = resourceLoader.getResource("classpath:"+path);
        return resource.getFile();
    }
}
